﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

using System.Collections;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Data.Odbc;
using System.Data;

namespace sgsBase
{
	/// <summary>
	/// Should contain some very basic static data elements. 
	/// Since this is not database specific, it should only set such things
	/// up.
	/// </summary>
    public class BaseStaticData
    {
        private static bool loaded = false;
		//private static string m_appname = "";

		public static Dictionary<string, string> _data_list;
		//public static List<DbThreadHolder> DbConnThreads;
		//public static Dictionary<string, DbConnector> DbConnectors;
		public static string BaseDB = "";
		public static string BaseApp = "";

        #region Properties
		//VosFlores12
		public static string EmailServerIP
		{
			get	{ return dataAt("email_server"); }
		}

		public static string EmailUser
		{
			get	{return dataAt("email_user");}
		}
		public static string EmailPass
		{
			get	{return dataAt("email_pass");}
		}
		public static int EmailPort
		{
			get	{return intAt("email_port");}
		}
        public static string NotifyDeveloper
        {
            get	{return dataAt("notify_developer");}
        }

		public static string NotifyTest
		{
			get { return dataPullAt("notify_test"); }
		}
        public static string RunningSystem
        {
            get { return dataAt("system_id"); }
        }
		//public static string DeveloperPC
		//{
		//    get
		//    {
		//        return RegistryInfo.CfgGetName("DeveloperPC");
		//    }
		//}
        //public static string PrintOutPutLocation
        //{
        //    get
        //    {
        //        return RegistryInfo.CfgGetPOLocation("PrintOutPutLoc");
        //    }
        //}
        

		#endregion

        protected static string dataAt(string i)
        {
            loadValues();
			try
			{
				if (!_data_list.ContainsKey(i))
					return "";
				return _data_list[i];
			}
			catch
			{
				return "";
			}
        }

		protected static string dataPullAt(string inp)
		{
			try
			{
				DbAppStaticdata asd = new DbAppStaticdata();
				asd.DataId = inp;
				if (asd.Select())
					return asd.DataValue;

				return "";
			}
			catch
			{
				return "";
			}
		}

		protected static int intAt(string i)
		{
			return CASTHelper.Integer(dataAt(i));
		}
		protected static decimal decimalAt(string i)
		{
			return CASTHelper.Decimal(dataAt(i));
		}
		public static void Reload()
		{
			//DbConnectors = null;
			//DbConnThreads = null;
			loaded = false;
			if (_data_list != null) 
			_data_list.Clear();
			loadValues();
			return;
		}
        private static void loadValues()
        {
            if (loaded)
                return;

            loaded = true;

			_data_list = new Dictionary<string, string>();

			DbAppStaticdata asd = new DbAppStaticdata();
			asd.Select();

			while (asd.HasData)
			{
				_data_list.Add(asd.DataId, asd.DataValue);
				asd.MoveNext();
			}

			//DbInterface dbi = new DbInterface();
			//DataTable   dt  = dbi.Query("select * from app_staticdata"); // where data_warehouse = " + ws.RunningInWarehouse());

			//foreach (DataRow dr in dt.Rows)
			//{
			//    _data_list.Add(dr["data_id"].ToString().Trim(), dr["data_value"].ToString().Trim());
			//}
        }

        public BaseStaticData()
        {

        }


    }
}
